﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
          "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>编辑器</title>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
    <script type="text/javascript" charset="utf-8" src="../Common/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="../Common/ueditor/ueditor.all.min.js"> </script>
    <!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
    <!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
    <script type="text/javascript" charset="utf-8" src="../Common/ueditor/lang/zh-cn/zh-cn.js"></script>

    <style type="text/css">
        div {
            width: 100%;
        }
    </style>
</head>
<body>
    <script id="editor" type="text/plain" style="width:100%; ">
    </script>

    <script type="text/javascript">
        var CPWebRootPath = parent.CPWebRootPath;
        function CPGetQuery(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");//不区分大小写 
            var r = window.location.search.substr(1).match(reg);
            if (r != null)
                return unescape(r[2]);
            return null;
        }
        var TableName = CPGetQuery("TableName"); 
        var FieldName = CPGetQuery("FieldName");
        var CPFormDataIndex = CPGetQuery("CPFormDataIndex");
        var IFrameHeight = CPGetQuery("IFrameHeight");
        document.getElementById("editor").style.height = (Number(IFrameHeight) -140) + "px";
    //实例化编辑器
    //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
        var formControl;
        var ue = UE.getEditor('editor', {
            allowDivTransToP: false
        }).ready(function () {
            //this是当前创建的编辑器实例
            var s = parent.CPFormGlobal_Scope.GetFieldValue(TableName, FieldName, CPFormDataIndex);
           // console.log(s);
            if (s != undefined) {
                this.setContent(s);
            }
            this.addListener('contentChange', function () {
                try {
                    console.log(getHTML());
                    parent.CPFormGlobal_Scope.SetFieldValue(TableName, FieldName, CPFormDataIndex, getHTML());
                } catch (e) {; }
            })
        });
        function setHTML(sHtml) {
            UE.getEditor('editor').setContent(sHtml);
        }
        function getHTML() {
            return UE.getEditor('editor').getContent();
        }
         
    </script>
</body>
</html>